#pragma once

#include "TypeDefin.h"

#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;
/*HJJ QQ479287006
 *
 * */
int sum = 0;

void sumNumbers_R(TreeNode *root, string temp) {
    if (root == nullptr) {
        sum += stoi(temp);
        return;
    }

    if ((root->left == nullptr && root->right == nullptr)) {

        sum = sum + stoi(temp + to_string(root->val));
        return;

    }

    //   if(root->left)
    sumNumbers_R(root->left, temp + to_string(root->val));

    //  if(root->right)
    sumNumbers_R(root->right, temp + to_string(root->val));


}

int sumNumbers(TreeNode *root) {
    sumNumbers_R(root, "");

    return sum;
}